<extend name="Layout/ins_popup"/>
<block name="content">
	<style>
		.layui-form-item {
			padding-top: 0px;
			padding-bottom: 0px;
			margin: 0px;
		}
		.x-box {
			background: #FFFFFF;
			margin-top: 10px;
			margin-bottom: 10px;
		}
		.x-box-body {
			padding-top: 10px;
			padding-bottom: 10px;
		}
		.layui-inline {
			margin-right: 0px !important;
		}
	</style>
	<input type="hidden" name="ajax" id="ajax" value="1">
	<div class="popup-frame">
		<div class="popup-header">
			<div class="pull-left">
				<h1>跳转条件</h1>
			</div>
			<div class="pull-right">
				<a id="btn_save" class="btn">确定</a>
				<a id="btn_close" class="btn btn-return">关闭</a>
			</div>
		</div>
		<div class="popup-body">
			<div class="popup-body-scroll">
				<div class="popup-content">
					<form id="form_data" name="form_data" method="post" >
						<input name="condition_name" id="condition_name" type="hidden">
						<input name="step_id" id="step_id" type="hidden" value="{$step_id}">
						<div class="x-box">
							<div class="x-box-body">
								
									<div class="layui-inline">
										<div class="input-inline col-12">
											<strong>第一组</strong>
										</div>
										<div class="input-inline col-12 x-select">
											<select class="input " name="key_11" id="key_11">
												<option value="">请选择</option>
												{:fill_option($udf_field)}
											</select>
										</div>
										<div class="input-inline col-12 x-select" >
											<select class="input" name="filter_11" id="filter_11">
												<option value="eq">=</option>
												<option value="neq">&lt;&gt;</option>
												<option value="gt">&gt;</option>
												<option value="egt">&gt;=</option>
												<option value="lt">&lt;</option>
												<option value="elt">&lt;=</option>
												<option value="like">包含</option>
												<option value="nolike">不包含</option>
											</select>
										</div>
										<div class="col-11 input-inline">
											<input  class="input" type="text" id="val_11" name="val_11" >
										</div>
									</div>
								</div>
								
									<div class="layui-inline" >
										<div class="col-12 input-inline x-select">
											<select class="input" name="logic_12" id="logic_12">
												<option value="and">并且</option>
												<option value="or">或</option>
											</select>
										</div>
										<div class="col-12 input-inline x-select">
											<select class="input" name="key_12" id="key_12">
												<option value="">请选择</option>
												{:fill_option($udf_field)}
											</select>
										</div>
										<div class="col-12 input-inline x-select">
											<select class="input" name="filter_12" id="filter_12">
												<option value="eq">=</option>
												<option vaue="neq"><></option>
												<option value="gt">></option>
												<option value="egt">>=</option>
												<option value="lt"><</option>
												<option value="elt"><=</option>
												<option value="like">包含</option>
												<option value="nolike">不包含</option>
											</select>
										</div>
										<div class="col-11 input-inline">
											<input  class="input" type="text" id="val_12" name="val_12" >
										</div>
									</div>
								</div>
								
									<div class="col-12 input-inline x-select">
										<select class="input" name="logic_13" id="logic_13">
											<option value="and">并且</option>
											<option value="or">或</option>
										</select>
									</div>
									<div class="col-12 input-inline x-select">
										<select class="input" name="key_13" id="key_13">
											<option value="">请选择</option>
											{:fill_option($udf_field)}
										</select>
									</div>
									<div class="col-12 input-inline x-select">
										<select class="input" name="filter_13" id="filter_13">
											<option value="eq">=</option>
											<option value="neq">&lt;&gt;</option>
											<option value="gt">&gt;</option>
											<option value="egt">&gt;=</option>
											<option value="lt">&lt;</option>
											<option value="elt">&lt;=</option>
											<option value="like">包含</option>
											<option value="nolike">不包含</option>
										</select>
									</div>
									<div class="col-11 input-inline">
										<input  class="input" type="text" id="val_13" name="val_13" >
									</div>
								</div>
							</div>
						</div>
						
							<div class="col-12 x-select input-inline">
								<select class="input" name="logic_group" id="logic_group">
									<option value="and">并且</option>
									<option value="or">或</option>
								</select>
							</div>
						</div>
						<div class="x-box"  >
							<div class="x-box-body">
								<div class="layui-form-item" >
									<div class="layui-inline">
										<div class="input-inline col-12">
											<strong>第二组</strong>
										</div>
										<div class="input-inline col-12 x-select">
											<select class="input" name="key_21" id="key_21">
												<option value="">请选择</option>
												{:fill_option($udf_field)}
											</select>
										</div>
										<div class="input-inline col-12  x-select">
											<select class="input" name="filter_21" id="filter_21">
												<option value="eq">=</option>
												<option value="neq">&lt;&gt;</option>
												<option value="gt">&gt;</option>
												<option value="egt">&gt;=</option>
												<option value="lt">&lt;</option>
												<option value="elt">&lt;=</option>
												<option value="like">包含</option>
												<option value="nolike">不包含</option>
											</select>
										</div>
										<div class="input-inline col-11">
											<input  class="input" type="text" id="val_21" name="val_21" >
										</div>
									</div>
								</div>
								<div class="layui-form-item" >
									<div class="layui-inline">
										<div class="input-inline col-12  x-select">
											<select class="input" name="logic_22" id="logic_22">
												<option value="and">并且</option>
												<option value="or">或</option>
											</select>
										</div>
										<div class="input-inline col-12  x-select">
											<select class="input" name="key_22" id="key_22">
												<option value="">请选择</option>
												{:fill_option($udf_field)}
											</select>
										</div>
										<div class="input-inline col-12  x-select">
											<select class="input" name="filter_22" id="filter_22">
												<option value="eq">=</option>
												<option value="neq">&lt;&gt;</option>
												<option value="gt">&gt;</option>
												<option value="egt">&gt;=</option>
												<option value="lt">&lt;</option>
												<option value="elt">&lt;=</option>
												<option value="like">包含</option>
												<option value="nolike">不包含</option>
											</select>
										</div>
										<div class="input-inline col-11">
											<input  class="input" type="text" id="val_22" name="val_22" >
										</div>
									</div>
								</div>
								<div class="layui-form-item" >
									<div class="input-inline col-12 x-select">
										<select class="input" name="logic_23" id="logic_23">
											<option value="and">并且</option>
											<option value="or">或</option>
										</select>
									</div>
									<div class="input-inline col-12 x-select">
										<select class="input" name="key_23" id="key_23">
											<option value="">请选择</option>
											{:fill_option($udf_field)}
										</select>
									</div>
									<div class="input-inline col-12 x-select">
										<select class="input" name="filter_23" id="filter_23">
											<option value="eq">=</option>
											<option value="neq">&lt;&gt;</option>
											<option value="gt">&gt;</option>
											<option value="egt">&gt;=</option>
											<option value="lt">&lt;</option>
											<option value="elt">&lt;=</option>
											<option value="like">包含</option>
											<option value="nolike">不包含</option>
										</select>
									</div>
									<div class="input-inline col-11">
										<input  class="input" type="text" id="val_23" name="val_23" >
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</block>

<block name="js">
	<script>
		var index = parent.layer.getFrameIndex(window.name);
		layui.use(['global'], function() {
			var $ = layui.jquery;

			$("#btn_save").on('click', function() {
				$val_11 = $('#val_11').val();
				$val_12 = $('#val_12').val();
				$val_13 = $('#val_13').val();
				$val_21 = $('#val_21').val();
				$val_22 = $('#val_22').val();
				$val_23 = $('#val_23').val();

				$str_condition_1 = '';
				if ($val_11 != '') {
					$key_val = $('#key_11 option:checked').val();
					if ($key_val == '') {
						layer.msg('请选择字段');
						$('#key_11').focus();
						return false;
					}
					$key_name = $('#key_11 option:checked').text();
					$filter_name = $('#filter_11 option:checked').text();
					$str_condition_1 = ' ' + $key_name + $filter_name + $val_11;
				}

				if ($val_12 != '') {
					$key_val = $('#key_12 option:checked').val();
					if ($key_val == '') {
						layer.msg('请选择字段');
						$('#key_12').focus();
						return false;
					}
					$logic_name = $('#logic_12 option:checked').text();
					$key_name = $('#key_12 option:checked').text();
					$filter_name = $('#filter_12 option:checked').text();
					$str_condition_1 += ' ' + $logic_name + ' ' + $key_name + $filter_name + $val_12;
				}

				$str_condition_2 = '';
				if ($val_13 != '') {
					$key_val = $('#key_13 option:checked').val();
					if ($key_val == '') {
						layer.msg('请选择字段');
						$('#key_13').focus();
						return false;
					}
					$logic_name = $('#logic_13 option:checked').text();
					$key_name = $('#key_13 option:checked').text();
					$filter_name = $('#filter_13 option:checked').text();
					$str_condition_1 += ' ' + $logic_name + ' ' + $key_name + $filter_name + $val_13;
				}

				if ($val_21 != '') {
					$key_val = $('#key_21 option:checked').val();
					if ($key_val == '') {
						layer.msg('请选择字段');
						$('#key_21').focus();
						return false;
					}
					$key_name = $('#key_21 option:checked').text();
					$filter_name = $('#filter_21 option:checked').text();
					$str_condition_2 = ' ' + $key_name + $filter_name + $val_21;
				}

				if ($val_22 != '') {
					$key_val = $('#key_22 option:checked').val();
					if ($key_val == '') {
						layer.msg('请选择字段');
						$('#key_22').focus();
						return false;
					}
					$logic_name = $('#logic_22 option:checked').text();
					$key_name = $('#key_22 option:checked').text();
					$filter_name = $('#filter_22 option:checked').text();
					$str_condition_2 += ' ' + $logic_name + ' ' + $key_name + $filter_name + $val_22;
				}

				if ($val_23 != '') {
					$key_val = $('#key_23 option:checked').val();
					if ($key_val == '') {
						layer.msg('请选择字段');
						$('#key_23').focus();
						return false;
					}
					$logic_name = $('#logic_23 option:checked').text();
					$key_name = $('#key_23 option:checked').text();
					$filter_name = $('#filter_23 option:checked').text();
					$str_condition_2 += ' ' + $logic_name + ' ' + $key_name + $filter_name + $val_23;
				}

				$logic_group = $("#logic_group option:checked").text();

				if ($str_condition_2 == '') {
					if ($str_condition_1 == '') {
						layer.msg('请选择');
					} else {
						$str_condition = $str_condition_1;
					}
				} else {
					$str_condition = '(' + $str_condition_1 + ') ' + $logic_group + ' (' + $str_condition_2 + ')';
				}

				$('#condition_name').val($str_condition);
				var vars = $("#form_data").serialize();
				send_ajax("{:url('condition')}", vars, function(data) {
					if (data.status) {
						$("#condition_name", parent.document).html($str_condition);
						parent.layer.close(index);
					}
				});
			});
			//关闭iframe
			$('#btn_close').click(function() {
				parent.layer.close(index);
			});
		});
	</script>
</block>
